<?php
/* 
 * Copyright (C) 2017 Antonio Ibáñez
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/**
 * Class to connect the controller to the views of the application.
 */
class Easier_rs_view {
    
    
    public static function show_main() {
        ?>
        <div class="wrap">
            <h1 id="title_easier">Easier Responsive Slider</h1>
            <h1>Discover a new world of customized post slider</h1>
            <?php echo "<a href='". admin_url(). "admin.php?page=easier_responsive_slider&add_new=yes'>Añadir nuevo Slider</a>" ?>
            <div>
                <table>
                    <thead>
                        <tr>
                            <th>ID Slider</th>
                            <th>Name</th>
                            <th>Number Slides</th>
                            <th>Shortcode</th>
                            <th>Edit</th>
                            <th>Delete</th>
                        </tr>
                    </thead>
                    <tbody>
                        <tr>
                <?php
                    $dir = plugin_dir_path( __FILE__ );
                     require_once $dir.'easier_rs_database.php';
                     $db = new Easier_rs_database();
                     $sliders = $db->easier_get_db();
                     if (empty($sliders)) {
                         echo "<td colspan='6'>En estos momentos no hay ningún Slider</td>";
                     }
                ?>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
        <?php
    }
	
    /**
     * Function to show the view with the information needed.
     * @param type $view It is the url of the view.
     * @param type $data It is the data needed in the view.
     */
    public static function show_add_slider() {
        $categories = get_categories( array(
            'orderby' => 'name'
        ));
            ?>
        <div class="wrap">
            <h1 id="title_easier">Easier Responsive Slider</h1>
            <h1>Create a new customize post slider</h1>
            <form id="easier_rs_form" action="<?php echo "admin.php?page=easier_responsive_slider" ?>" method="post">
                <div class="div_easier_form"><label for="slider-title">Slider title*</label><input type="text" name="slider-title" required></div>
                <button id="option_settings" class="option_menu">Settings</button>
                <button id="option_type" class="option_menu">Type of Slider</button>
                <div id="content_slider">
                    <div class="div_easier_form">
                        <label for="tax_time">Period of time to get posts</label>
                        <input type="text">
                        <select name="tax_time">
                            <option value="">Select the period</option>
                            <option value="hour">Hour</option>
                            <option value="week">Week</option>
                            <option value="month">Month</option>
                            <option value="year">Year</option>
                        </select>
                    </div>
                    <div class="div_easier_form">
                        <label for="number_post">Number of posts</label>
                        <input name="number_post" type="text">
                    </div>
                    <div class="div_easier_form">
                        <label for="tax_categoies">Post categories</label>
                <?php
                printf('<select name="tax_categories">');
                printf('<option value="">Select a category</option>');
                foreach ( $categories as $c ){
                    printf('<option value="%2$s">%1$s</option>',
                    esc_html($c->name),
                    esc_html($c->term_id )        
                            );
                }
                printf('</select>');  
                ?>
                    </div>
                    <div class="div_easier_form">
                        <label for="sort_type">Sort by</label>
                        <select name="sort_type">
                            <option value="date">Publishing date</option>
                            <option value="comments">Number of comments</option>
                            <option value="title">Post title</option>
                        </select>
                    </div>
                    <div class="div_easier_form">
                        <label for="order_by">Order by</label>
                        <span class="radio_admin"><input type="radio" name="order_by" value="1" checked="checked"></span><label>Ascending</label>
                        <span class="radio_admin"><input type="radio" name="order_by" value="2" ></span><label>Descending</label>
                    </div>
                </div>
                <div id="content_settings">
                    <div class="div_easier_form">
                        <label for="width">Dimensions</label>
                        <input name="width" type="text" placeholder="width" value="750">
                        x
                        <input name="height" type="text" placeholder="height" value="500">
                        px
                        <br>
                        <p>if width=0 the slider will take 100% of width</p>
                    </div>
                    <div class="div_easier_form">
                        <label>Hide Slider on small screen</label>
                        <input type="text" name="hide_slider" placeholder="width">
                        px
                        <br>
                        <p>Hide Slider when resolution screen is smaller than, if empty, it won't hide</p>
                    </div>
                    <div class="div_easier_form">
                        <label for="back_fit">Background fit</label>
                        <input type="radio" name="back_fit" value="smart" checked="checked">Smart
                        <input type="radio" name="back_fit" value="cover">Cover
                        <input type="radio" name="back_fit" value="contain">Contain
                    </div>
                    <div class="div_easier_form">
                        <label for="align_slider">Align</label>
                        <input type="radio" name="align_slider" value="center" cheched='checked'>Center
                        <input type="radio" name="align_slider" value="left">Left
                        <input type="radio" name="align_slider" value="right">Right
                    </div>
                    <div class="div_easier_form">
                        <label for="effect_slider">Effect</label>
                        <select name="effect_slider">
                            <option value="default">Default</option>
                            <option value="fade">Fade</option>
                            <option value="slide">Slide</option>
                        </select>
                    </div>
                    <div class="div_easier_form">
                        <label for="effect_time">Effect duration</label>
                        <input type="text" name="effect_time" value='0'>
                        ms
                        <p>Define the time for the slide to take effect</p>
                    </div>
                    <div class="div_easier_form">
                        <label for="start_slide">Start with Slider</label>
                        <input type="text" name="start_slide" value="1">
                        <p>The slider will start with the specified slide. You can use the value 0 for random</p>
                    </div>
                </div>
                <button id="submit" type="submit" name="submit" value="set_options">Guardar</button>
            </form>
        </div>
        <?php
    }
        
}
